import 'package:flutter/material.dart';
import 'package:flutter_lang/flutter_lang.dart';
import 'package:route_manager/wx_navigator.dart';
import 'package:wallet_home/model/wallet_list_model.dart';
import 'package:wallet_home/page/theme/colors.dart';
import 'package:wallet_home/tools/theme_utils.dart';

// import 'package:wallet_authentication/config.dart';
import 'package:wallet_home/walletdetail/models/private_key_export_list_model.dart';
import 'package:wallet_home/walletdetail/pages/export_private_key_page.dart';
import 'package:wallet_home/widget/coins_manager.dart';

import '../../module_config.dart';

class PrivateKeyExportListPage extends StatefulWidget {
  const PrivateKeyExportListPage({Key key}) : super(key: key);

  @override
  _PrivateKeyExportListPageState createState() =>
      _PrivateKeyExportListPageState();
}

class _PrivateKeyExportListPageState extends State<PrivateKeyExportListPage> {
  List<PrivateKeyExportListModel> itemList = [];
  List<CoinsBean> coinBeanList = CoinManager().allSelectedCoinList;

  @override
  void initState() {
    super.initState();
  }

  _getExportList(){
    itemList.clear();
    for (int i = 0; i < coinBeanList.length; i++) {
      itemList.add(PrivateKeyExportListModel(
          Image.asset(coinBeanList[i].img.toString(),
              width: 30, height: 30, package: ModuleConfig.moduleName),
          coinBeanList[i].title.toString() + "${WXLang.$t("home_private_key_export",package: ModuleConfig.moduleName)}",
          Icon(
            Icons.keyboard_arrow_right,
            color: ThemeUtils.getThemeColor(
                context: context,
                brightnessColor: Colors.grey[500],
                darkColor: Colors.white),
          )));
    }
  }

  @override
  Widget build(BuildContext context) {
    _getExportList();
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        elevation: 0,
        title: Text(
          "${WXLang.$t("home_private_key_export",package: ModuleConfig.moduleName)}",
          style: TextStyle(
              color: ThemeUtils.getThemeColor(
                  context: context,
                  brightnessColor: Colors.white,
                  darkColor: Colors.grey[200])),
        ),
        leading: IconButton(
          icon: Icon(
            Icons.arrow_back,
            color: ThemeUtils.getThemeColor(
                context: context,
                brightnessColor: Colors.white,
                darkColor: Colors.grey[200])
          ),
          onPressed: () {
              WXNavigator.pop(context: context);
          },
        ),
      ),
      body: Container(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Expanded(
              child: ListView.separated(
                  itemBuilder: (BuildContext context, int index) {
                    return InkWell(
                      onTap: () {
                        WXNavigator.pushNamed(
                            context: context,
                            routeName: '/checkPINPage',
                            moduleName: "wallet_authentication",
                            arguments: {
                              'isHiddenBack': false,
                              'onCallBack': (String value) {
                                WXNavigator().popAndPushNamed(
                                    "/exportPrivateKeyPage",
                                    context: context,
                                    arguments:
                                        "${coinBeanList[index].privateKey}");
                              }
                            });
                      },
                      child: Container(
                        height: 50,
                        color: ThemeUtils.getThemeColor(
                            context: context,
                            brightnessColor: Colors.white,
                            darkColor: Colours.dark_bg_color),
                        padding: EdgeInsets.fromLTRB(15, 0, 12, 0),
                        child: Row(
                          children: <Widget>[
                            itemList[index].titleIcon,
                            Container(
                                margin: EdgeInsets.only(left: 10),
                                child: Text("${itemList[index].title}")),
                            Spacer(),
                            itemList[index].itemTail,
                          ],
                        ),
                      ),
                    );
                  },
                  separatorBuilder: (BuildContext context, int index) {
                    return Container(
                      margin: EdgeInsets.only(left: 15),
                      height: 1,
                      width: double.infinity,
                      color: Colors.grey[200]
                    );
                  },
                  itemCount: itemList.length),
            )
          ],
        ),
      ),
    );
  }
}
